import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.URL;
import java.util.List;
import java.util.Properties;

import javax.swing.*;

//required libraries for the basic PDF viewer
import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.WindowManagementCallback;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;
import org.icepdf.ri.util.PropertiesManager;

public class ViewPdf extends JFrame{
	ViewPdf(String f){
/**
 * First we verify that the file passed into us is a PDF
 **/
		String ffile = f.toLowerCase();
		if(ffile.endsWith("pdf")){
			try{
				//the meat and potatoes of the pdf viewer GUI
				SwingController controller = new SwingController();
				controller.setIsEmbeddedComponent(true);
				//set the viewController embeddable flag
				DocumentViewController viewCtrl = 
					controller.getDocumentViewController();
				JPanel viewComponentPanel = new JPanel();
				viewComponentPanel.add(viewCtrl.getViewContainer());
				
				// add copy keyboard command support
				ComponentKeyBinding.install(controller, viewComponentPanel);

				// add interactive mouse link annotation support via callback
				controller.getDocumentViewController().setAnnotationCallback(
						new org.icepdf.ri.common.MyAnnotationCallback(
								controller.getDocumentViewController()));
				// this holds everything
				JFrame masterPanel = new JFrame();

				masterPanel.getContentPane().add(viewComponentPanel);
				masterPanel.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
				controller.openDocument(ffile);
				// this hardsets the viewing to a single page
				controller.setPageViewMode(
					DocumentViewControllerImpl.ONE_PAGE_VIEW,false);
								
				//display the viewer
				masterPanel.pack();
				masterPanel.setVisible(true);
				
				JFrame view  = controller.getViewerFrame();
				view.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
			}
			catch(IllegalArgumentException e){
				JOptionPane.showMessageDialog(null,"File is not a PDF!");
			}
			catch(NullPointerException e){
				JOptionPane.showMessageDialog(null, "I'm sorry, I can't Find that File. "
						+ "Please Try again");
			}
		}
	}
}

	